In this notebook we plot the permutahedron of order 4 which is a 3-dimensional polyhedron living in a 4-dimensional space. It is defined as the convex hull of all permutations of $(0, 1, 2, 3)$.


In [1]:
using Combinatorics, Polyhedra
v = vrep(collect(permutations([0, 1, 2, 3])))


Out[1]:
V-representation Polyhedra.PointsHull{Int64,Array{Int64,1},Int64}:
24-element iterator of Array{Int64,1}:
 [0, 1, 2, 3]
 [0, 1, 3, 2]
 [0, 2, 1, 3]
 [0, 2, 3, 1]
 [0, 3, 1, 2]
 [0, 3, 2, 1]
 [1, 0, 2, 3]
 [1, 0, 3, 2]
 [1, 2, 0, 3]
 [1, 2, 3, 0]
 [1, 3, 0, 2]
 [1, 3, 2, 0]
 [2, 0, 1, 3]
 [2, 0, 3, 1]
 [2, 1, 0, 3]
 [2, 1, 3, 0]
 [2, 3, 0, 1]
 [2, 3, 1, 0]
 [3, 0, 1, 2]
 [3, 0, 2, 1]
 [3, 1, 0, 2]
 [3, 1, 2, 0]
 [3, 2, 0, 1]
 [3, 2, 1, 0]

To plot a polyhedron, we need both the H-representation and V-representation so we will need a library to do representation conversion. We choose CDD in floating point arithmetic.


In [2]:
using CDDLib
p4 = polyhedron(v, CDDLib.Library())


Out[2]:
Polyhedron CDDLib.Polyhedron{Float64}:
24-element iterator of Array{Float64,1}:
 [0.0, 1.0, 2.0, 3.0]
 [0.0, 1.0, 3.0, 2.0]
 [0.0, 2.0, 1.0, 3.0]
 [0.0, 2.0, 3.0, 1.0]
 [0.0, 3.0, 1.0, 2.0]
 [0.0, 3.0, 2.0, 1.0]
 [1.0, 0.0, 2.0, 3.0]
 [1.0, 0.0, 3.0, 2.0]
 [1.0, 2.0, 0.0, 3.0]
 [1.0, 2.0, 3.0, 0.0]
 [1.0, 3.0, 0.0, 2.0]
 [1.0, 3.0, 2.0, 0.0]
 [2.0, 0.0, 1.0, 3.0]
 [2.0, 0.0, 3.0, 1.0]
 [2.0, 1.0, 0.0, 3.0]
 [2.0, 1.0, 3.0, 0.0]
 [2.0, 3.0, 0.0, 1.0]
 [2.0, 3.0, 1.0, 0.0]
 [3.0, 0.0, 1.0, 2.0]
 [3.0, 0.0, 2.0, 1.0]
 [3.0, 1.0, 0.0, 2.0]
 [3.0, 1.0, 2.0, 0.0]
 [3.0, 2.0, 0.0, 1.0]
 [3.0, 2.0, 1.0, 0.0]

The permutahedron lives in a 4-dimension space but is 3-dimensional as it is contained in the hyperplane $x_1 + x_2 + x_3 + x_4 = 0 + 1 + 2 + 3 = 6$. We choose an orthogonal basis of this hyperplane: $(1, -1, 0, 0)$, $(1, 1, -2, 0)$ and $(1, 1, 1, -3)$.


In [3]:
v1 = [1, -1,  0,  0]
v2 = [1,  1, -2,  0]
v3 = [1,  1,  1, -3];

We project the polyhedron in this basis to obtain a full dimensional 3-dimensional polyhedron living in a 3-dimensional space.


In [4]:
p3 = project(p4, [v1 v2 v3])


Out[4]:
Polyhedron CDDLib.Polyhedron{Float64}:
14-element iterator of HalfSpace{Float64,Array{Float64,1}}:
 HalfSpace([-0.0, 3.26599, -1.1547], 6.0)
 HalfSpace([1.41421, 0.816497, -1.1547], 3.9999999999999996)
 HalfSpace([-0.0, -0.0, -1.1547], 2.0)
 HalfSpace([-1.41421, 0.816497, -1.1547], 3.999999999999999)
 HalfSpace([-2.82843, -1.63299, -1.1547], 6.0)
 HalfSpace([-0.0, -1.63299, -1.1547], 4.000000000000001)
 HalfSpace([-1.41421, -0.816497, 1.1547], 4.000000000000002)
 HalfSpace([-0.0, -3.26599, 1.1547], 6.000000000000011)
 HalfSpace([-2.82843, 1.63299, 1.1547], 5.999999999999995)
 HalfSpace([2.82843, -1.63299, -1.1547], 6.0)
 HalfSpace([1.41421, -0.816497, 1.1547], 4.0000000000000036)
 HalfSpace([-0.0, -0.0, 1.1547], 2.0)
 HalfSpace([-0.0, 1.63299, 1.1547], 3.9999999999999964)
 HalfSpace([2.82843, 1.63299, 1.1547], 5.9999999999999964)

To get a plottable object, we transform the polyhedron into a mesh as follows.


In [5]:
m = Polyhedra.Mesh(p3);

We can now plot this mesh with MeshCat or Makie as follows:


In [ ]:
using MeshCat
vis = Visualizer()
setobject!(vis, m)
IJuliaCell(vis)

In [ ]:
using Makie
mesh(m, color=:blue)

In [ ]:
using Makie
wireframe(m)

In [ ]: